#!/usr/bin/env python
#coding=utf-8
from HrefDataCatcher import HrefDataCatcher
from fiction.models import Fiction, Chapter
import urllib

fiction_list = Fiction.object.all()

for t_fiction in fiction_list:

    usock = urllib.urlopen(t_fiction.url)
    parser = HrefDataCatcher()
    parser.feed(usock.read().decode('gbk'))
    parser.close()
    usock.close()
    for row in parser.data:
        t_fiction.chapter_set.create(chapter = row)
